package com.pocketpets.ui.map;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.location.Location;

import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
import com.pocketpets.gamelogic.II;
import com.pocketpets.gamelogic.ILocationLogic;
import com.pocketpets.globaldata.GlobalData;

public class ItemizedOverlay extends com.google.android.maps.ItemizedOverlay {

	// ================================================================
	// Fields
	// ================================================================

	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	private Context mContext;

	// ================================================================
	// Contructors
	// ================================================================

	public ItemizedOverlay(Drawable defaultMarker) {
		super(boundCenterBottom(defaultMarker));
		populate();
		// TODO Auto-generated constructor stub
	}

	public ItemizedOverlay(Drawable defaultMarker, Context context) {
		super(boundCenterBottom(defaultMarker));
		populate();
		mContext = context;
	}

	// ================================================================
	// Inheried methods
	// ================================================================

	public void addOverlay(OverlayItem overlay) {
		mOverlays.add(overlay);
		populate();
	}

	@Override
	protected OverlayItem createItem(int i) {
		// TODO Auto-generated method stub
		return mOverlays.get(i);
	}

	@Override
	public int size() {
		// TODO Auto-generated method stub
		return mOverlays.size();
	}

	@Override
	protected boolean onTap(int index) {
		
		OverlayItem item = mOverlays.get(index);
		double radius=1000.0;
		GlobalData gbData=GlobalData.getInstance();
		Location markerLocation=new Location("Maker");
		markerLocation.setLatitude(item.getPoint().getLatitudeE6()/1E6);
		markerLocation.setLongitude(item.getPoint().getLongitudeE6()/1E6);
		
		if (true)
		
		//if (markerLocation.distanceTo(gbData.getUserLocation()) <radius)
		{
			AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
			dialog.setTitle("Change Location");
			dialog.setMessage("GOGOGO"+GlobalData.getInstance().getUserLocation().getLatitude()+" "+GlobalData.getInstance().getUserLocation().getLongitude());
			//dialog.setMessage("GOGOGO"+markerLocation.distanceTo(gbData.getUserLocation()) );
					dialog.show();
		}
		else
		{
		
		AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
		dialog.setTitle(item.getTitle());
		dialog.setMessage(item.getSnippet()+markerLocation.distanceTo(gbData.getUserLocation()) );
				dialog.show();
		}
//		OverlayItem item = mOverlays.get(index);
//		AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
//		dialog.setTitle(item.getTitle());
//		dialog.setMessage(item.getSnippet());
//		dialog.show();
		return true;
	}

	@Override
	public void draw(android.graphics.Canvas canvas,MapView mapView,boolean shadow) {

		if (!shadow)
			super.draw(canvas, mapView, false);

			}
}
